package com.initcap.saml;

/**
 * @author initcap
 * @date Created in 2024/6/14 20:33.
 */
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.security.saml2.provider.service.authentication.Saml2AuthenticatedPrincipal;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
public class HomeController {

    @RequestMapping("/")
    public String home(@AuthenticationPrincipal Saml2AuthenticatedPrincipal principal, Model model) {
        model.addAttribute("name", principal.getName());
        model.addAttribute("email", principal.getFirstAttribute("email"));
        model.addAttribute("firstName", principal.getFirstAttribute("firstName"));
        model.addAttribute("lastName", principal.getFirstAttribute("lastName"));
        model.addAttribute("userAttributes", principal.getAttributes());
        return "home";
    }

}
